#include "CarroCristiane.h"

#include <GL/glu.h>
#include "gllib/Objects.h"

void CarroCristiane::draw() {
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

    float mat_specular[] = {0.7, 0.7, 0.7, 1.0};
    float shininess = 20;

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialf(GL_FRONT, GL_SHININESS, shininess);

    glPushMatrix();
        glScaled(3.0,3.0,3.0);
        desenhaEstrutura();
        desenhaRodas();
        desenhaFarois();
        desenhaVidros();
    glPopMatrix();

    glDisable(GL_COLOR_MATERIAL);
}

void CarroCristiane::desenhaRodas(){
    // roda dir-frente
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.1,0.2,0.1);
        gllibCylinder(0.08,0.05,30);
    glPopMatrix();

    // roda dir-tras
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(-0.1,0.2,0.1);
        gllibCylinder(0.08,0.05,30);
    glPopMatrix();

    // roda esq-frente
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.1,-0.2,0.1);
        gllibCylinder(0.08,0.05,30);
    glPopMatrix();

    // roda esq-tras
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(-0.1,-0.2,0.1);
        gllibCylinder(0.08,0.05,30);
    glPopMatrix();

    // pneu reserva-traseira
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,0.0,0.0,1.0);
        glTranslated(0.0,0.27,0.0);
        gllibCylinder(0.08,0.05,30);
    glPopMatrix();

    // pino frente
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.1,0.0,0.1);
        gllibCylinder(0.01,0.4,30);
    glPopMatrix();

    // pino tras
    glPushMatrix();
        glColor3f(1, 0, 0.1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(-0.1,0.0,0.1);
        gllibCylinder(0.01,0.4,30);
    glPopMatrix();
}

void CarroCristiane::desenhaVidros(){
    // vidro dir
    glPushMatrix();
        glColor3f(0, 1, 1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.0,-0.175,-0.150);
        glScaled(1.0,0.025,0.38);
        gllibCube(0.3);
    glPopMatrix();

    // vidro esq
    glPushMatrix();
        glColor3f(0, 1, 1);
        glRotated(90,1.0,0.0,0.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.0,0.175,-0.150);
        glScaled(1.0,0.025,0.38);
        gllibCube(0.3);
    glPopMatrix();

    // vidro frente
    glPushMatrix();
        glColor3f(0, 1, 1);
        glRotated(90,1.0,0.0,0.0);
        glRotated(90,0.0,0.0,1.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.0,-0.175,-0.150);
        glScaled(1.0,0.025,0.38);
        gllibCube(0.3);
    glPopMatrix();

    // vidro tras
    glPushMatrix();
        glColor3f(0, 1, 1);
        glRotated(90,1.0,0.0,0.0);
        glRotated(90,0.0,0.0,1.0);
        //(x,y,z)=(frente,direita,baixo)
        glTranslated(0.0,0.175,-0.150);
        glScaled(1.0,0.025,0.38);
        gllibCube(0.3);
    glPopMatrix();
}

void CarroCristiane::desenhaFarois(){
    // farol dir-frente
    glPushMatrix();
        glColor3f(0.0,0.2,1.0);
        glRotated(90,0.0,0.0,1.0);
        //(x,y,z)=(cima,tras,direita)
        glTranslated(0.03,-0.27,0.13);
        gllibCylinder(0.035,0.025,30);
    glPopMatrix();

    // farol esq-frente
    glPushMatrix();
        glColor3f(0.0,0.2,1.0);
        glRotated(90,0.0,0.0,1.0);
        //(x,y,z)=(cima,tras,direita)
        glTranslated(0.03,-0.27,-0.13);
        gllibCylinder(0.035,0.025,30);
    glPopMatrix();

    // farol dir-tras
    glPushMatrix();
        glColor3f(0.0,0.2,1.0);
        glRotated(90,0.0,0.0,1.0);
        //(x,y,z)=(cima,tras,direita)
        glTranslated(0.03,0.27,0.13);
        gllibCylinder(0.035,0.025,30);
    glPopMatrix();

    // farol esq-tras
    glPushMatrix();
        glColor3f(0.0,0.2,1.0);
        glRotated(90,0.0,0.0,1.0);
        //(x,y,z)=(cima,tras,direita)
        glTranslated(0.03,0.27,-0.13);
        gllibCylinder(0.035,0.025,30);
    glPopMatrix();
}

void CarroCristiane::desenhaEstrutura(){
    // baixo
    glPushMatrix();
        glColor3f(1, 1, 0);
        glTranslated(0.0,0.0,0.0);
        glScaled(1.0,0.4,0.7);
        gllibCube(0.5);
    glPopMatrix();

    // cima
    glPushMatrix();
        glColor3f(1, 1, 0);
        glTranslated(0.0,0.15,0.0);
        glScaled(0.7,0.3,0.7);
        gllibCube(0.5);
    glPopMatrix();
}
